package class4;

/**
 * https://leetcode.cn/problems/power-of-two/
 * 2的幂
 * 思路：如果一个数是2的幂，则这个数 (n & -n) == n
 */
public class Code08_isPowerOfTwo {
    public static void main(String[] args) {
//        int x = 5;
        int x = 4;
        boolean res = isPowerOfTwo(x);
        System.out.println("res = " + res);
        // 00000000000000000000000000000101
        // 11111111111111111111111111111011
    }

    public static boolean isPowerOfTwo(int n) {
        return n > 0 && n == (n & -n);
    }
}
